﻿namespace jzgl.Controller
{
    using jzgl.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    internal class DesignerDB
    {
        private SqlConnection conn = null;
        private ConnDB conndb = new ConnDB();
        private DataTable table = null;
        private SysUser user = new SysUser();

        public DesignerDB()
        {
            this.conn = this.conndb.GetConnString();
        }

        public int Add_Designer(Designer des)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "insert into Designer values('" + des._DesignerName + "','" + des._DesignerRemark + "')";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_Designer(Designer des)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from Designer where DesignerId='" + des._DesignerId + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_Designer2(string id)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from Designer where DesignerRemark='" + id + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public DataTable Show_Designer()
        {
            try
            {
                try
                {
                    string sql = "select * from Designer";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public void Show_Designer(ComboBox box)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from Designer";
                    this.conndb.comboxDataBind(box, sqlstr, "DesignerId", "DesignerName");
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public void Show_Designer(DataGridView dgv)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from Designer";
                    this.conndb.dgvDataBind(dgv, sqlstr);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public int Update_Designer(Designer des)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { "update Designer set DesignerRemark='", des._DesignerRemark, "',DesignerName='", des._DesignerName, "'  where  DesignerId='", des._DesignerId, "'" });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Update_Designer_2(Designer des, string name)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "update Designer set DesignerRemark='" + des._DesignerRemark + "',DesignerName='" + des._DesignerName + "'  where  DesignerName='" + name + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }
    }
}

